package mark.wxming.twotigerlock.lock;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 全局锁接口
 * @author twotiger-wxm.
 * @date 2019/4/23.
 */
public interface ILockHandler {

    /**
     * 获取锁  如果锁可用   立即返回true，  否则返回false
     * @param iLockIdentify
     * @return
     */
    public boolean tryLock(ILockIdentify iLockIdentify);

    /**
     * 锁在给定的等待时间内空闲，则获取锁成功 返回true， 否则返回false
     * @param iLockIdentify
     * @param timeout
     * @param unit
     * @return
     */
    public boolean tryLock(ILockIdentify iLockIdentify, long timeout, TimeUnit unit);

    /**
     * 如果锁空闲立即返回   获取失败 一直等待
     * @param iLockIdentify
     */
    public void lock(ILockIdentify iLockIdentify);

    /**
     * 释放锁
     * @param iLockIdentify
     */
    public void unLock(ILockIdentify iLockIdentify);

    /**
     * 批量获取锁  如果全部获取   立即返回true, 部分获取失败 返回false
     * @param iLockIdentifyList
     * @return
     */
    public boolean tryLock(List<ILockIdentify> iLockIdentifyList);

    /**
     * 锁在给定的等待时间内空闲，则获取锁成功 返回true， 否则返回false
     * @param iLockIdentifyList
     * @param timeout
     * @param unit
     * @return
     */
    public boolean tryLock(List<ILockIdentify> iLockIdentifyList, long timeout,
                           TimeUnit unit);

    /**
     * 批量释放锁
     * @param iLockIdentifyList
     */
    public void unLock(List<ILockIdentify> iLockIdentifyList);

}
